package edu.whu.rose.clock.ssql.search.dp;

import java.util.HashMap;

import edu.whu.rose.clock.ssql.util.ExpandableIntArray;
import edu.whu.rose.clock.ssql.util.SubgraphMatrix;

public class ShortestDistance {

	private final SubgraphMatrix subgraph;
	
	private int[][] sDistances;
	
	public ShortestDistance(SubgraphMatrix subgraph) {
		this.subgraph = subgraph;3
		this.sDistances = new int[subgraph.getN()][];
	}
	
	public void compute(int vertex) {
		HashMap<Integer, Integer> distances = new HashMap<Integer, Integer>();
		int dis = 0;
		distances.put(new Integer(vertex), new Integer(dis));
		
		int[] current = new int[]{vertex};
		while(current.length > 0) {
			ExpandableIntArray eia = new ExpandableIntArray();
			dis++;
			for (int i = 0; i < current.length; i++) {
				int[] neighbors = subgraph.genNeighbors(current[i]);
				for (int j = 0; j < neighbors.length; j++) {
					Integer k = new Integer(neighbors[j]);
					Integer d = distances.get(k);
					if (d == null) {
						distances.put(k, new Integer(dis));
						eia.add(d.intValue());
					}
				}
			}
			current = eia.toArray();
		}
	}
}
